local fuling = fk.CreateSkill {
  name = "th_fuling",
}

fuling:addAcquireEffect(function(self, player)
  local room = player.room
  room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
    for _, move in ipairs(e.data) do
      if move.to == player and move.toArea == Player.Hand then
        for _, info in ipairs(move.moveInfo) do
          local id = info.cardId
          local card = Fk:getCardById(id)
          if room:getCardArea(id) == Card.PlayerHand and room:getCardOwner(id) == player and
          (card.trueName == "slash" or card:isCommonTrick()) then
            room:setCardMark(card, "@@th_fuling-inhand-turn", 1)
          end
        end
      end
    end
  end, Player.HistoryTurn)
end)
fuling:addLoseEffect(function(self, player)
  local room = player.room
  for cid, cmark in pairs(room.card_marks) do
    for name, _ in pairs(cmark) do
      if name == "@@th_fuling-inhand-turn" then
        room:setCardMark(Fk:getCardById(cid), name, 0)
      end
    end
  end
end)

fuling:addEffect(fk.AfterCardsMove, {
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self, true)
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, move in ipairs(data) do
      if move.to == player and move.toArea == Player.Hand then
        for _, info in ipairs(move.moveInfo) do
          local id = info.cardId
          local card = Fk:getCardById(id)
          if room:getCardArea(id) == Card.PlayerHand and room:getCardOwner(id) == player and
          (card.trueName == "slash" or card:isCommonTrick()) then
            room:setCardMark(card, "@@th_fuling-inhand-turn", 1)
          end
        end
      end
    end
  end,
})
fuling:addEffect("targetmod", {
  bypass_distances = function(self, player, skill, card, to)
    return player:hasSkill("th_fuling") and card and card:getMark("@@th_fuling-inhand-turn") ~= 0 and
    (card.trueName == "slash" or card:isCommonTrick())
  end,
  extra_target_func = function(self, player, skill, card)
    if player:hasSkill("th_fuling") and card and card:getMark("@@th_fuling-inhand-turn") ~= 0 and
    (card.trueName == "slash" or card:isCommonTrick()) then
      return 1
    end
  end
})

Fk:loadTranslationTable{
  ["th_fuling"] = "附灵",
  [":th_fuling"] = "锁定技，你使用本回合获得的【杀】或普通锦囊牌无距离限制且目标上限+1。",

  ["@@th_fuling-inhand-turn"] = "附灵",
}

return fuling